<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品信息</title>
</head>
<body>
<button onclick="findAll()">查询所有</button>

<script src="../static/js/axios.js"></script>
<script>
    function findAll() {
        axios.get("http://localhost:8080/list")
            .then(res => {
                let resp = res.data
                if (resp.code === 1) {
                    let arr = resp.data
                    let table = document.createElement("table")
                    let tr = document.createElement("tr")
                    tr.innerHTML= "<td>id</td><td>商品名称</td><td>价格</td><td>种类</td>"
                    table.appendChild(tr)
                    arr.forEach(e => {
                        let tr = document.createElement("tr")
                        let td = document.createElement("td")
                        td.innerText = e.id
                        tr.appendChild(td)
                        let td2 = document.createElement("td")
                        td2.innerText = e.goodsName
                        tr.appendChild(td2)
                        let td3 = document.createElement("td")
                        td3.innerText = e.goodsPrice
                        tr.appendChild(td3)
                        let td4 = document.createElement("td")
                        td4.innerText = e.categoryId
                        tr.appendChild(td4)
                        table.appendChild(tr)
                    })
                    console.log(table)
                    document.querySelector("body").appendChild(table)
                }

            }).catch(err => {
            console.log(err)
        })
    }
</script>
</body>
</html>